package com.example.demo.jvm;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Description TODO
 * @Author BG490350
 * @Date 2023/6/14 15:31
 **/
public class Test_CGLIB {


    public static void main(String[] _args) {
        MethodInterceptor interceptor = new MethodInterceptor() {

            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                System.out.println(">>>>>before intercept");
                Object o = methodProxy.invokeSuper(obj, args);
                System.out.println(">>>>>end intercept");
                return o;
            }
        };
        com.example.demo.jvm.Person person = (com.example.demo.jvm.Person) Enhancer.create(com.example.demo.jvm.Person.class, interceptor);
        person.eat();
    }

}
